package com.dding.cms.base.web.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TreeNode implements Serializable {

	private static final long serialVersionUID = 5313832663736528043L;

	private String name;
	private String id;
	private String pId;
	private boolean open;
	private String isParent;
	private Object userdata;
	private List<TreeNode> children = new ArrayList<TreeNode>();

	public TreeNode(TreeNode node) {
		this.name = node.name;
		this.id = node.id;
		this.open = node.open;
		this.isParent = node.isParent;
		this.pId = node.pId;
		this.userdata = node.userdata;
		this.children = new ArrayList<TreeNode>(node.children);
	}

	public TreeNode(String name, String id) {
		this.name = name;
		this.id = id;
	}

	public TreeNode() {
	}

	public String getId() {
		return id;
	}

	public Object getUserdata() {
		return userdata;
	}

	public void setUserdata(Object userdata) {
		this.userdata = userdata;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	public List<TreeNode> getChildren() {
		return children;
	}

	public boolean removeChildren(String treeId) {
		for (Iterator<TreeNode> iterator = children.iterator(); iterator
				.hasNext();) {
			TreeNode node = (TreeNode) iterator.next();
			if (node.getId().equals(treeId)) {
				iterator.remove();
			}
		}
		return true;
	}

	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}

	public void addChildren(TreeNode node) {
		children.add(node);
	}

	public String getpId() {
		return pId;
	}

	public void setpId(String pId) {
		this.pId = pId;
	}

	@Override
	public String toString() {
		return "{id=" + id + ", pId=" + pId + ", name=" + name + ", open="
				+ open + ", isParent=" + isParent + "}";
	}

	public String getIsParent() {
		return isParent;
	}

	public void setIsParent(String isParent) {
		this.isParent = isParent;
	}
}
